﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.BLL.LeaderOperate;

namespace MINERP.LeaderOperate
{
    public partial class FrmAutoAssion : Form
    {
        public FrmAutoAssion()
        {
            InitializeComponent();
        }
        public FrmAutoAssion(bool inIsStart)
        {
            InitializeComponent();

            isStart = inIsStart;
        }

        public FrmLeaderOperate leader { get; set; }


        private bool isStart = false;

        private void FrmAutoAssion_Load(object sender, EventArgs e)
        {
            this.textEditTimeSpan.Text = Properties.Settings.Default.AutoAssionTaskTimeSpan;
            this.textEditTaskNum.Text = Properties.Settings.Default.AutoAssionTaskNum;
            checkEditISCallBack.Checked = Properties.Settings.Default.IsCallBack;
            checkEditIsAssionLeader.Checked = Properties.Settings.Default.IsAssionToLeader;
            if (isStart)
            {
                this.simpleButtonOK.Text = "关闭自动分配";
            }
            else
            {
                this.simpleButtonOK.Text = "开启自动分配";
            }
            progressBarControl1.Visible = false;
            timerPross.Enabled = false;

        }
        public delegate void TimerControl(bool isCallBack);

        public event TimerControl StartTimer;
        public event TimerControl EndtTimer;

        private void simpleButtonOK_Click(object sender, EventArgs e)
        {

            Properties.Settings.Default.AutoAssionTaskTimeSpan = textEditTimeSpan.Text;
            Properties.Settings.Default.AutoAssionTaskNum = textEditTaskNum.Text;
            Properties.Settings.Default.IsCallBack = checkEditISCallBack.Checked;
            Properties.Settings.Default.Save();
            //if (isStart)
            //{
            //    this.simpleButtonOK.Text = "关闭自动分配";
            //    //关闭
            //    EndtTimer(checkEditISCallBack.Checked);
            //    labelControl_Num.Visible = true;
            //    progressBarControl1.Visible = true;
            //    //progressBarControl1.Properties;
            //    //this.Close();
            //}
            //else
            //{
            //    this.simpleButtonOK.Text = "开启自动分配";
            //    //开启
            //    labelControl_Num.Visible = false;
            //    progressBarControl1.Visible = false;
            //    StartTimer(checkEditISCallBack.Checked);
            //    //this.Close();
            //}
            if (simpleButtonOK.Text.Equals("开启自动分配"))
            {
                textEditTimeSpan.Enabled = false;
                textEditTaskNum.Enabled = false;
                checkEditISCallBack.Enabled = false;

                progressBarControl1.Visible = true;
                simpleButtonOK.Text = "关闭自动分配";
                StartTimer(checkEditISCallBack.Checked);
                timerPross.Enabled = true;
            }
            else
            {
                textEditTimeSpan.Enabled = true;
                textEditTaskNum.Enabled = true;
                checkEditISCallBack.Enabled = true;

                progressBarControl1.Visible = false;
                simpleButtonOK.Text = "开启自动分配";
                EndtTimer(checkEditISCallBack.Checked);
                timerPross.Enabled = false;
            }
        }

        private void simpleButtonCancel_Click(object sender, EventArgs e)
        {
            if (System.Windows.Forms.DialogResult.OK == MessageBox.Show("关闭窗口会关闭自动分配任务，确定关闭吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
            {
                this.Close();

            }
        }

        private void FrmAutoAssion_FormClosing(object sender, FormClosingEventArgs e)
        {

            //if (System.Windows.Forms.DialogResult.OK == MessageBox.Show("关闭窗口会关闭自动分配任务，确定关闭吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
            //{
            EndtTimer(checkEditISCallBack.Checked);

            //}
            //else
            //{

            //}
        }

        private int proPosion = 0;
        private void timerPross_Tick(object sender, EventArgs e)
        {
            proPosion = proPosion % 100;
            proPosion = proPosion + 1;
            progressBarControl1.Position = proPosion;
        }

        private void labelControl_Num_Click(object sender, EventArgs e)
        {

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            notifyIcon1.Visible = true;
            leader.Visible = false;
            this.Visible = false;
        }

        private void tsBackForm_Click(object sender, EventArgs e)
        {
            leader.Visible = true;
            this.Visible = true;

        }

        private void checkEditIsAssionLeader_CheckedChanged(object sender, EventArgs e)
        {
            if (checkEditIsAssionLeader.Checked)
            {
                Properties.Settings.Default.IsAssionToLeader = true;
            }
            else
            {
                Properties.Settings.Default.IsAssionToLeader = false;

            }
            Properties.Settings.Default.Save();
        }
    }
}
